package com.ctsi.system.strategy.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.ctsi.system.service.IEmpService;
import com.ctsi.system.service.IOrgService;
import com.ctsi.system.strategy.IDataScope;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 本部门及以下数据权限
 *
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/9 16:21
 */
@Component(IDataScope.DEPT_WITH_CHILD)
@RequiredArgsConstructor
public class DeptWithChildDataScope implements IDataScope {
    private final IEmpService empService;
    private final IOrgService orgService;

    @Override
    public List<Long> getOrgIds(List<Long> orgIds, Long userId) {
        Long orgId = empService.getOrgId(userId);
        List<Long> childIdListById = orgService.getChildIdListWithSelfById(orgId);
        List<Long> resultList = CollectionUtil.newArrayList(childIdListById);
        resultList.add(orgId);
        return resultList;
    }
}